#!/usr/bin/node

//删除目录

const fs = require('fs'),
      err = console.error;
      //dir = process.argv[2];
      
var opt,src,lnk;

switch(process.argv.length) {
  case 4:{   //node 13-ln.js src lik
    src = process.argv[2];
    lnk = process.argv[3];
    
    try {
      fs.linkSync(src, lnk);
    } catch(e) {
      err(e.message);
      process.exit(1);
    }

    break;
  }
  case 5:{  //符号链接node 13-ln.js -s src link
    src = process.argv[3];
    lnk = process.argv[4];

    opt = process.argv[2];
    
    if(opt === '-s') {
      try {
        fs.symlinkSync(src, lnk);
      } catch(e) {
        err(e.messsage);
        process.exit(2);
      }
    } else {
      err('命令行参数没有-s，不正确');
    }

    break;
  }

  default:
    err('命令行输入不正确');
}
